

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>Librados (Python) &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/doctools.js"></script>
        <script src="../../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="Ceph SQLite VFS" href="../libcephsqlite/" />
    <link rel="prev" title="LibradosPP (C++)" href="../libradospp/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../../">Ceph 存储集群</a></li>
          <li class="breadcrumb-item"><a href="../">Ceph 存储集群 API</a></li>
      <li class="breadcrumb-item active">Librados (Python)</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../../_sources/rados/api/python.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../">Ceph 存储集群</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../configuration/">配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../operations/">运维</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../man/">    手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../troubleshooting/">故障排除</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../">APIs</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../librados-intro/">librados 简介</a></li>
<li class="toctree-l3"><a class="reference internal" href="../librados/">librados (C)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../libradospp/">librados (C++)</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">librados (Python)</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id2">安装</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">开工</a></li>
<li class="toctree-l4"><a class="reference internal" href="#api">集群句柄 API</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id14">输入/输出上下文 API</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id17">对象接口</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../libcephsqlite/">libcephsqlite (SQLite)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../objclass-sdk/">object class</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="librados-python">
<span id="id1"></span><h1>Librados (Python)<a class="headerlink" href="#librados-python" title="Permalink to this heading"></a></h1>
<p><code class="docutils literal notranslate"><span class="pre">rados</span></code> 模块是 <code class="docutils literal notranslate"><span class="pre">librados</span></code> 的 Python 瘦封装。</p>
<section id="id2">
<h2>安装<a class="headerlink" href="#id2" title="Permalink to this heading"></a></h2>
<p>要安装 Ceph 的 Python 库，看看 <a class="reference external" href="../librados-intro#getting-librados-for-python">获取 librados 的 Python 接口</a> 。</p>
</section>
<section id="id3">
<h2>开工<a class="headerlink" href="#id3" title="Permalink to this heading"></a></h2>
<p>你可以用 Python 实现你自己的 Ceph 客户端。
下面的教程会向你展示如何导入 Ceph 的 Python 门口、
连接到集群、并以 <code class="docutils literal notranslate"><span class="pre">client.admin</span></code> 身份执行对象操作。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>要使用 Ceph 的 Python 库，你必须有正常运行的 Ceph 集群、
及其访问权限。要快速配起一个集群，看 <a class="reference external" href="../../../start">入门手册</a> 。</p>
</div>
<p>首先创建一个 Ceph 客户端的 Python 源码文件。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
</style><span class="prompt1">vim<span class="w"> </span>client.py</span>
</pre></div></div><section id="id4">
<h3>导入模块<a class="headerlink" href="#id4" title="Permalink to this heading"></a></h3>
<p>要使用 <code class="docutils literal notranslate"><span class="pre">rados</span></code> 模块，需在源码文件里导入。</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span> <span class="kn">import</span> <span class="nn">rados</span>
</pre></div>
</div>
</section>
<section id="id5">
<h3>配置集群句柄<a class="headerlink" href="#id5" title="Permalink to this heading"></a></h3>
<p>连接 Ceph 存储集群前，得先创建集群句柄。默认情况下，
集群句柄假设集群名为 <code class="docutils literal notranslate"><span class="pre">ceph</span></code> （即部署工具的默认值，
而且我们的 <a class="reference external" href="../../../start">入门手册</a> 也是）、用户名为 <code class="docutils literal notranslate"><span class="pre">client.admin</span></code> 。
你可以根据自己的环境更改默认值。</p>
<p>要连接到 Ceph 存储集群，你的应用程序需要知道去哪里找到 Ceph 监视器。
给你的应用程序指定 Ceph 配置文件的路径即可提供此信息，
配置文件里有初始的 Ceph 监视器位置。</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span> <span class="kn">import</span> <span class="nn">rados</span><span class="o">,</span> <span class="nn">sys</span>
<span class="linenos">2</span>
<span class="linenos">3</span> <span class="c1">#Create Handle Examples.</span>
<span class="linenos">4</span> <span class="n">cluster</span> <span class="o">=</span> <span class="n">rados</span><span class="o">.</span><span class="n">Rados</span><span class="p">(</span><span class="n">conffile</span><span class="o">=</span><span class="s1">&#39;ceph.conf&#39;</span><span class="p">)</span>
<span class="linenos">5</span> <span class="n">cluster</span> <span class="o">=</span> <span class="n">rados</span><span class="o">.</span><span class="n">Rados</span><span class="p">(</span><span class="n">conffile</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="linenos">6</span> <span class="n">cluster</span> <span class="o">=</span> <span class="n">rados</span><span class="o">.</span><span class="n">Rados</span><span class="p">(</span><span class="n">conffile</span> <span class="o">=</span> <span class="s1">&#39;ceph.conf&#39;</span><span class="p">,</span> <span class="n">conf</span> <span class="o">=</span> <span class="nb">dict</span> <span class="p">(</span><span class="n">keyring</span> <span class="o">=</span> <span class="s1">&#39;/path/to/keyring&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>确保 <code class="docutils literal notranslate"><span class="pre">conffile</span></code> 参数提供了 Ceph 配置文件的路径和文件名，
你可以用 <code class="docutils literal notranslate"><span class="pre">sys</span></code> 模块避免写死 Ceph 配置文件路径和文件名。</p>
<p>你的 Python 客户端还需要一个客户端密钥环，在本例中，我们默认使用 <code class="docutils literal notranslate"><span class="pre">client.admin</span></code> 的密钥。
如果你想在创建集群句柄的时候指定密钥环，可以用 <code class="docutils literal notranslate"><span class="pre">conf</span></code> 参数。
另外，你也可以在 Ceph 配置文件中指定密钥环文件的路径。例如，
你可以在 Ceph 配置文件里加上类似如下的：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">keyring</span> <span class="o">=</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">ceph</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">admin</span><span class="o">.</span><span class="n">keyring</span>
</pre></div>
</div>
<p>通过 Python 修改配置的额外细节见 <a class="reference internal" href="#id11">配置</a>。</p>
</section>
<section id="id6">
<h3>连接到集群<a class="headerlink" href="#id6" title="Permalink to this heading"></a></h3>
<p>配置好集群句柄后，你就可以连接到集群了。通过到集群的连接，
你可以执行库的各种方法来获取集群信息。</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos"> 1</span> <span class="kn">import</span> <span class="nn">rados</span><span class="o">,</span> <span class="nn">sys</span>
<span class="linenos"> 2</span>
<span class="linenos"> 3</span> <span class="n">cluster</span> <span class="o">=</span> <span class="n">rados</span><span class="o">.</span><span class="n">Rados</span><span class="p">(</span><span class="n">conffile</span><span class="o">=</span><span class="s1">&#39;ceph.conf&#39;</span><span class="p">)</span>
<span class="linenos"> 4</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">librados version: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">cluster</span><span class="o">.</span><span class="n">version</span><span class="p">())))</span>
<span class="linenos"> 5</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Will attempt to connect to: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">cluster</span><span class="o">.</span><span class="n">conf_get</span><span class="p">(</span><span class="s1">&#39;mon host&#39;</span><span class="p">))))</span>
<span class="linenos"> 6</span>
<span class="hll"><span class="linenos"> 7</span> <span class="n">cluster</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
</span><span class="linenos"> 8</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Cluster ID: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cluster</span><span class="o">.</span><span class="n">get_fsid</span><span class="p">()))</span>
<span class="linenos"> 9</span>
<span class="linenos">10</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">Cluster Statistics&quot;</span><span class="p">)</span>
<span class="linenos">11</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;==================&quot;</span><span class="p">)</span>
<span class="linenos">12</span> <span class="n">cluster_stats</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">get_cluster_stats</span><span class="p">()</span>
<span class="linenos">13</span>
<span class="linenos">14</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">cluster_stats</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="linenos">15</span>     <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
</pre></div>
</div>
<p>默认情况下， Ceph 的认证的 <code class="docutils literal notranslate"><span class="pre">开启的</span></code> ，应用程序需要知道密钥环的位置。
<code class="docutils literal notranslate"><span class="pre">python-ceph</span></code> 模块没有默认位置，所以你得指定密钥环路径。
指定密钥环最简单的方法就是写入 Ceph 配置文件，
下面的 Ceph 配置文件实例用的就是 <code class="docutils literal notranslate"><span class="pre">client.admin</span></code> 密钥环。</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span><span class="w"> </span><span class="k">[global]</span>
<span class="linenos">2</span><span class="w"> </span><span class="c1"># ... elided configuration</span>
<span class="linenos">3</span><span class="w"> </span><span class="na">keyring</span><span class="o">=</span><span class="s">/path/to/keyring/ceph.client.admin.keyring</span>
</pre></div>
</div>
</section>
<section id="id7">
<h3>管理存储池<a class="headerlink" href="#id7" title="Permalink to this heading"></a></h3>
<p>连接到集群后，你可以用 <code class="docutils literal notranslate"><span class="pre">Rados</span></code> API 管理存储池。
你可以罗列存储池、检查一个存储池是否存在、新建存储池和删除存储池。</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos"> 1</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">Pool Operations&quot;</span><span class="p">)</span>
<span class="linenos"> 2</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;===============&quot;</span><span class="p">)</span>
<span class="linenos"> 3</span>
<span class="linenos"> 4</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Available Pools&quot;</span><span class="p">)</span>
<span class="linenos"> 5</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;----------------&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos"> 6</span> <span class="n">pools</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">list_pools</span><span class="p">()</span>
</span><span class="linenos"> 7</span>
<span class="linenos"> 8</span> <span class="k">for</span> <span class="n">pool</span> <span class="ow">in</span> <span class="n">pools</span><span class="p">:</span>
<span class="linenos"> 9</span>     <span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="p">)</span>
<span class="linenos">10</span>
<span class="linenos">11</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Create &#39;test&#39; Pool&quot;</span><span class="p">)</span>
<span class="linenos">12</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;------------------&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">13</span> <span class="n">cluster</span><span class="o">.</span><span class="n">create_pool</span><span class="p">(</span><span class="s1">&#39;test&#39;</span><span class="p">)</span>
</span><span class="linenos">14</span>
<span class="linenos">15</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Pool named &#39;test&#39; exists: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">cluster</span><span class="o">.</span><span class="n">pool_exists</span><span class="p">(</span><span class="s1">&#39;test&#39;</span><span class="p">))))</span>
<span class="linenos">16</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Verify &#39;test&#39; Pool Exists&quot;</span><span class="p">)</span>
<span class="linenos">17</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;-------------------------&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">18</span> <span class="n">pools</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">list_pools</span><span class="p">()</span>
</span><span class="linenos">19</span>
<span class="linenos">20</span> <span class="k">for</span> <span class="n">pool</span> <span class="ow">in</span> <span class="n">pools</span><span class="p">:</span>
<span class="linenos">21</span>     <span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="p">)</span>
<span class="linenos">22</span>
<span class="linenos">23</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Delete &#39;test&#39; Pool&quot;</span><span class="p">)</span>
<span class="linenos">24</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;------------------&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">25</span> <span class="n">cluster</span><span class="o">.</span><span class="n">delete_pool</span><span class="p">(</span><span class="s1">&#39;test&#39;</span><span class="p">)</span>
</span><span class="linenos">26</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Pool named &#39;test&#39; exists: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">cluster</span><span class="o">.</span><span class="n">pool_exists</span><span class="p">(</span><span class="s1">&#39;test&#39;</span><span class="p">))))</span>
</pre></div>
</div>
</section>
<section id="id8">
<h3>输入/输出上下文<a class="headerlink" href="#id8" title="Permalink to this heading"></a></h3>
<p>读出或写入 Ceph 存储集群需要有输入输出上下文（ ioctx ）。
你可以用 <code class="docutils literal notranslate"><span class="pre">Rados</span></code> 类的 <code class="docutils literal notranslate"><span class="pre">open_ioctx()</span></code> 或 <code class="docutils literal notranslate"><span class="pre">open_ioctx2()</span></code> 方法创建 ioctx 。
<code class="docutils literal notranslate"><span class="pre">ioctx_name</span></code> 参数是存储池的名字、
<code class="docutils literal notranslate"><span class="pre">pool_id</span></code> 是你想要使用的存储池的 ID 。</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span> <span class="n">ioctx</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">open_ioctx</span><span class="p">(</span><span class="s1">&#39;data&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>或者</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span>     <span class="n">ioctx</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">open_ioctx2</span><span class="p">(</span><span class="n">pool_id</span><span class="p">)</span>
</pre></div>
</div>
<p>拿到 I/O 上下文之后，你就能读写对象、扩展属性、
以及其他很多操作了。完成操作后，
必须关闭连接。例如：</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Closing the connection.&quot;</span><span class="p">)</span>
<span class="linenos">2</span> <span class="n">ioctx</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</section>
<section id="id9">
<h3>对象的写入、读取和删除<a class="headerlink" href="#id9" title="Permalink to this heading"></a></h3>
<p>创建 I/O 上下文之后，你就能向集群写入对象了。如果你向一个不存在的对象写入，
Ceph 会创建它。如果你向一个已存在的对象写入， Ceph 会覆盖它
（除非你指定了一个范围，那么它就只覆盖那段范围）。
你可以从集群读出对象（和对象的某一段）。也能从集群删除对象。例如：</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Writing object &#39;hw&#39; with contents &#39;Hello World!&#39; to pool &#39;data&#39;.&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">2</span><span class="n">ioctx</span><span class="o">.</span><span class="n">write_full</span><span class="p">(</span><span class="s2">&quot;hw&quot;</span><span class="p">,</span> <span class="s2">&quot;Hello World!&quot;</span><span class="p">)</span>
</span><span class="linenos">3</span>
<span class="linenos">4</span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">Contents of object &#39;hw&#39;</span><span class="se">\n</span><span class="s2">------------------------</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">5</span><span class="nb">print</span><span class="p">(</span><span class="n">ioctx</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s2">&quot;hw&quot;</span><span class="p">))</span>
</span><span class="linenos">6</span>
<span class="linenos">7</span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Removing object &#39;hw&#39;&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">8</span><span class="n">ioctx</span><span class="o">.</span><span class="n">remove_object</span><span class="p">(</span><span class="s2">&quot;hw&quot;</span><span class="p">)</span>
</span></pre></div>
</div>
</section>
<section id="xattrs">
<h3>XATTRS 的读取和写入<a class="headerlink" href="#xattrs" title="Permalink to this heading"></a></h3>
<p>创建对象后，你可以向对象写入扩展属性（ XATTR ）、还能从对象读出 XATTR 。例如：</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="linenos">1</span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">Writing XATTR &#39;lang&#39; with value &#39;en_US&#39; to object &#39;hw&#39;&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">2</span><span class="n">ioctx</span><span class="o">.</span><span class="n">set_xattr</span><span class="p">(</span><span class="s2">&quot;hw&quot;</span><span class="p">,</span> <span class="s2">&quot;lang&quot;</span><span class="p">,</span> <span class="s2">&quot;en_US&quot;</span><span class="p">)</span>
</span><span class="linenos">3</span>
<span class="linenos">4</span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">Getting XATTR &#39;lang&#39; from object &#39;hw&#39;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">5</span><span class="nb">print</span><span class="p">(</span><span class="n">ioctx</span><span class="o">.</span><span class="n">get_xattr</span><span class="p">(</span><span class="s2">&quot;hw&quot;</span><span class="p">,</span> <span class="s2">&quot;lang&quot;</span><span class="p">))</span>
</span></pre></div>
</div>
</section>
<section id="id10">
<h3>罗列对象<a class="headerlink" href="#id10" title="Permalink to this heading"></a></h3>
<p>如果你想检查存储池内的对象们，你可以检索出这些对象，
并通过对象迭代器挨个迭代出来。例如：</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="hll"><span class="linenos"> 1</span><span class="n">object_iterator</span> <span class="o">=</span> <span class="n">ioctx</span><span class="o">.</span><span class="n">list_objects</span><span class="p">()</span>
</span><span class="linenos"> 2</span>
<span class="linenos"> 3</span><span class="k">while</span> <span class="kc">True</span> <span class="p">:</span>
<span class="linenos"> 4</span>
<span class="linenos"> 5</span>    <span class="k">try</span> <span class="p">:</span>
<span class="hll"><span class="linenos"> 6</span>        <span class="n">rados_object</span> <span class="o">=</span> <span class="n">object_iterator</span><span class="o">.</span><span class="fm">__next__</span><span class="p">()</span>
</span><span class="hll"><span class="linenos"> 7</span>        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Object contents = </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">rados_object</span><span class="o">.</span><span class="n">read</span><span class="p">()))</span>
</span><span class="linenos"> 8</span>
<span class="linenos"> 9</span>    <span class="k">except</span> <span class="ne">StopIteration</span> <span class="p">:</span>
<span class="linenos">10</span>        <span class="k">break</span>
<span class="linenos">11</span>
<span class="linenos">12</span><span class="c1"># Or alternatively</span>
<span class="linenos">13</span><span class="p">[</span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Object contents = </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">read</span><span class="p">()))</span> <span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="n">ioctx</span><span class="o">.</span><span class="n">list_objects</span><span class="p">()]</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Object</span></code> 类提供了类似文件的接口让你访问对象，
可以读写内容和扩展属性。对象操作使用 I/O 上下文，
它还提供了额外功能和异步能力。</p>
</section>
</section>
<section id="api">
<h2>集群句柄 API<a class="headerlink" href="#api" title="Permalink to this heading"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">Rados</span></code> 类提供了一个进入 Ceph 存储守护进程的接口。</p>
<section id="id11">
<h3>配置<a class="headerlink" href="#id11" title="Permalink to this heading"></a></h3>
<p><code class="docutils literal notranslate"><span class="pre">Rados</span></code> 类提供了一些方法，可以获取和设置配置选项的值、
读取 Ceph 配置文件、并分析参数。
无需连接到 Ceph 存储集群就能调用下面的方法。有关配置的细节见 <a class="reference external" href="../../configuration">存储集群配置</a> 。</p>
<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.conf_get">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">conf_get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">option</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.conf_get" title="Permalink to this definition"></a></dt>
<dd><p>Rados.conf_get(self, unicode option: str) -&gt; Optional[str]</p>
<p>Get the value of a configuration option</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>option</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- which option to read</p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]</p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>value of the option or None</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.conf_set">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">conf_set</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">option</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">val</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.conf_set" title="Permalink to this definition"></a></dt>
<dd><p>Rados.conf_set(self, unicode option: str, unicode val: str)</p>
<p>Set the value of a configuration option</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>option</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- which option to set</p></li>
<li><p><strong>option</strong> -- value of the option</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">ObjectNotFound</span></code></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.conf_read_file">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">conf_read_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.conf_read_file" title="Permalink to this definition"></a></dt>
<dd><p>Rados.conf_read_file(self, unicode path: Optional[str] = None)</p>
<p>Configure the cluster handle using a Ceph config file.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>path</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]) -- path to the config file</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.conf_parse_argv">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">conf_parse_argv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.conf_parse_argv" title="Permalink to this definition"></a></dt>
<dd><p>Rados.conf_parse_argv(self, args: Sequence[str])</p>
<p>Parse known arguments from args, and remove; returned
args contain only those unknown to ceph</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.version">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">version</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.version" title="Permalink to this definition"></a></dt>
<dd><p>Rados.version(self) -&gt; Version</p>
<p>Get the version number of the <code class="docutils literal notranslate"><span class="pre">librados</span></code> C library.</p>
<dl class="field-list simple">
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Version</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>a tuple of <code class="docutils literal notranslate"><span class="pre">(major,</span> <span class="pre">minor,</span> <span class="pre">extra)</span></code> components of the
librados version</p>
</dd>
</dl>
</dd></dl>

</section>
<section id="id12">
<h3>连接管理<a class="headerlink" href="#id12" title="Permalink to this heading"></a></h3>
<p>配置好集群句柄后，你就能连接集群了，检查集群的 <code class="docutils literal notranslate"><span class="pre">fsid</span></code> 、检出集群统计信息、
然后断开（关闭）到集群的连接。你也可以断言集群句柄处于某种状态
（例如 configuring 、 connecting 等等）。</p>
<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.connect">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">connect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.connect" title="Permalink to this definition"></a></dt>
<dd><p>Rados.connect(self, int timeout: int = 0)</p>
<p>Connect to the cluster.  Use shutdown() to release resources.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>timeout</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- Any supplied timeout value is currently ignored.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.shutdown">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">shutdown</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.shutdown" title="Permalink to this definition"></a></dt>
<dd><p>Rados.shutdown(self)</p>
<p>Disconnects from the cluster.  Call this explicitly when a
Rados.connect()ed object is no longer used.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.get_fsid">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">get_fsid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.get_fsid" title="Permalink to this definition"></a></dt>
<dd><p>Rados.get_fsid(self) -&gt; str</p>
<p>Get the fsid of the cluster as a hexadecimal string.</p>
<dl class="field-list simple">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>cluster fsid</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.get_cluster_stats">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">get_cluster_stats</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.get_cluster_stats" title="Permalink to this definition"></a></dt>
<dd><p>Rados.get_cluster_stats(self) -&gt; Dict[str, int]</p>
<p>Read usage info about the cluster</p>
<p>This tells you total space, space used, space available, and number
of objects. These are not updated immediately when data is written,
they are eventually consistent.
:rtype: <code class="xref py py-class docutils literal notranslate"><span class="pre">Dict</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>]
:returns: contains the following keys:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">kb</span></code> (int) - total space</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">kb_used</span></code> (int) - space used</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">kb_avail</span></code> (int) - free space available</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_objects</span></code> (int) - number of objects</p></li>
</ul>
</div></blockquote>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="rados.Rados">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">rados.</span></span><span class="sig-name descname"><span class="pre">Rados</span></span><a class="headerlink" href="#rados.Rados" title="Permalink to this definition"></a></dt>
<dd><dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.require_state">
<span class="sig-name descname"><span class="pre">require_state</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">\*args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.require_state" title="Permalink to this definition"></a></dt>
<dd><p>检查一下 Rados 对象是否处于指定状态。</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>args</strong> -- Any number of states to check as separate arguments</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">RadosStateError</span></code></p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</section>
<section id="id13">
<h3>存储池操作<a class="headerlink" href="#id13" title="Permalink to this heading"></a></h3>
<p>要使用存储池操作方法，你必须先连接到 Ceph 存储集群。你可以列出可用存储池、
创建一个存储池、检验一个存储池是否存在、还能删除存储池。</p>
<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.list_pools">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">list_pools</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.list_pools" title="Permalink to this definition"></a></dt>
<dd><p>Rados.list_pools(self) -&gt; List[str]</p>
<p>Gets a list of pool names.</p>
<dl class="field-list simple">
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">List</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>list of pool names.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.create_pool">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">create_pool</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pool_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">crush_rule</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">auid</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.create_pool" title="Permalink to this definition"></a></dt>
<dd><p>Rados.create_pool(self, unicode pool_name: str, int crush_rule: Optional[int] = None, int auid: Optional[int] = None)</p>
<p>Create a pool:
- with default settings: if crush_rule=None and auid=None
- with a specific CRUSH rule: crush_rule given
- with a specific auid: auid given
- with a specific CRUSH rule and auid: crush_rule and auid given</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>pool_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the pool to create</p></li>
<li><p><strong>crush_rule</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>]) -- rule to use for placement in the new pool</p></li>
<li><p><strong>auid</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>]) -- id of the owner of the new pool</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.pool_exists">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">pool_exists</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pool_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.pool_exists" title="Permalink to this definition"></a></dt>
<dd><p>Rados.pool_exists(self, unicode pool_name: str) -&gt; bool</p>
<p>Checks if a given pool exists.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>pool_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the pool to check</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>whether the pool exists, false otherwise.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.delete_pool">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">delete_pool</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pool_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.delete_pool" title="Permalink to this definition"></a></dt>
<dd><p>Rados.delete_pool(self, unicode pool_name: str)</p>
<p>Delete a pool and all data inside it.</p>
<p>The pool is removed from the cluster immediately,
but the actual data is deleted in the background.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>pool_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the pool to delete</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="cli">
<h3>CLI 命令<a class="headerlink" href="#cli" title="Permalink to this heading"></a></h3>
<p>Ceph CLI 命令的内部用的是下面的 librados Python 绑定的方法。</p>
<p>要发出一个命令，选对方法和正确的目标。</p>
<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.mon_command">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">mon_command</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inbuf</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">target</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.mon_command" title="Permalink to this definition"></a></dt>
<dd><p>Send a command to the mon.</p>
<p>mon_command[_target](cmd, inbuf, outbuf, outbuflen, outs, outslen)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>cmd</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- JSON formatted string.</p></li>
<li><p><strong>inbuf</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>) -- optional string.</p></li>
<li><p><strong>timeout</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- This parameter is ignored.</p></li>
<li><p><strong>target</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Union</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>, <code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code>]) -- name or rank of a specific mon. Optional</p></li>
</ul>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-data docutils literal notranslate"><span class="pre">Tuple</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]</p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>(int ret, string outbuf, string outs)</p>
</dd>
</dl>
<p>Example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">json</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">Rados</span><span class="p">(</span><span class="n">conffile</span><span class="o">=</span><span class="s1">&#39;/etc/ceph/ceph.conf&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cmd</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">({</span><span class="s2">&quot;prefix&quot;</span><span class="p">:</span> <span class="s2">&quot;osd safe-to-destroy&quot;</span><span class="p">,</span> <span class="s2">&quot;ids&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;2&quot;</span><span class="p">],</span> <span class="s2">&quot;format&quot;</span><span class="p">:</span> <span class="s2">&quot;json&quot;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span><span class="o">.</span><span class="n">mon_command</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="sa">b</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.osd_command">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">osd_command</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">osdid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inbuf</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.osd_command" title="Permalink to this definition"></a></dt>
<dd><p>osd_command(osdid, cmd, inbuf, outbuf, outbuflen, outs, outslen)</p>
<dl class="field-list simple">
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-data docutils literal notranslate"><span class="pre">Tuple</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>(int ret, string outbuf, string outs)</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.mgr_command">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">mgr_command</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inbuf</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">target</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.mgr_command" title="Permalink to this definition"></a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-data docutils literal notranslate"><span class="pre">Tuple</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>]</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>(int ret, string outbuf, string outs)</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.pg_command">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">pg_command</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pgid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inbuf</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.pg_command" title="Permalink to this definition"></a></dt>
<dd><p>pg_command(pgid, cmd, inbuf, outbuf, outbuflen, outs, outslen)</p>
<dl class="field-list simple">
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-data docutils literal notranslate"><span class="pre">Tuple</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>]</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>(int ret, string outbuf, string outs)</p>
</dd>
</dl>
</dd></dl>

</section>
</section>
<section id="id14">
<h2>输入/输出上下文 API<a class="headerlink" href="#id14" title="Permalink to this heading"></a></h2>
<p>要向 Ceph 对象存储库写入和读出数据，必须创建一个输入/输出上下文（ ioctx ）。
<cite>Rados</cite> 类提供了 <cite>open_ioctx()</cite> 和 <cite>open_ioctx2()</cite> 方法。
其余 <code class="docutils literal notranslate"><span class="pre">ioctx</span></code> 操作包括 <cite>Ioctx</cite> 和其它类的调用方法。</p>
<dl class="py method">
<dt class="sig sig-object py" id="rados.Rados.open_ioctx">
<span class="sig-prename descclassname"><span class="pre">Rados.</span></span><span class="sig-name descname"><span class="pre">open_ioctx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ioctx_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Rados.open_ioctx" title="Permalink to this definition"></a></dt>
<dd><p>Rados.open_ioctx(self, unicode ioctx_name: str) -&gt; Ioctx</p>
<p>Create an io context</p>
<p>The io context allows you to perform operations within a particular
pool.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>ioctx_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the pool</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Ioctx</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Rados Ioctx object</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.require_ioctx_open">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">require_ioctx_open</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.require_ioctx_open" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.require_ioctx_open(self)</p>
<p>Checks if the rados.Ioctx object state is ‘open’</p>
<dl class="field-list simple">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p>IoctxStateError</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.get_stats">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">get_stats</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.get_stats" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.get_stats(self) -&gt; Dict[str, int]</p>
<p>Get pool usage statistics</p>
<dl class="field-list simple">
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Dict</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>]</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><p>dict contains the following keys:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">num_bytes</span></code> (int) - size of pool in bytes</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_kb</span></code> (int) - size of pool in kbytes</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_objects</span></code> (int) - number of objects in the pool</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_object_clones</span></code> (int) - number of object clones</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_object_copies</span></code> (int) - number of object copies</p></li>
<li><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">num_objects_missing_on_primary</span></code> (int) - number of objects</dt><dd><p>missing on primary</p>
</dd>
</dl>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_objects_unfound</span></code> (int) - number of unfound objects</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_objects_degraded</span></code> (int) - number of degraded objects</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_rd</span></code> (int) - bytes read</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_rd_kb</span></code> (int) - kbytes read</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_wr</span></code> (int) - bytes written</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_wr_kb</span></code> (int) - kbytes written</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.get_last_version">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">get_last_version</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.get_last_version" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.get_last_version(self) -&gt; int</p>
<p>Return the version of the last object read or written to.</p>
<p>This exposes the internal version number of the last object read or
written via this io context</p>
<dl class="field-list simple">
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>version of the last object used</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.close">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.close" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.close(self)</p>
<p>Close a rados.Ioctx object.</p>
<p>This just tells librados that you no longer need to use the io context.
It may not be freed immediately if there are pending asynchronous
requests on it, but you should not use an io context again after
calling this function on it.</p>
</dd></dl>

<section id="id15">
<h3>对象操作<a class="headerlink" href="#id15" title="Permalink to this heading"></a></h3>
<p>Ceph 存储集群把数据存储成了对象。你可以同步或异步地读写对象。
你可以从某个偏移量开始读写，每个对象有一个名字（键名）和数据。</p>
<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.aio_write">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">aio_write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">to_write</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">oncomplete</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">onsafe</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.aio_write" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.aio_write(self, unicode object_name: str, bytes to_write: bytes, int offset: int = 0, oncomplete: Optional[Callable[[Completion], None]] = None, onsafe: Optional[Callable[[Completion], None]] = None) -&gt; Completion</p>
<p>Write data to an object asynchronously</p>
<p>Queues the write and returns.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>object_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the object</p></li>
<li><p><strong>to_write</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>) -- data to write</p></li>
<li><p><strong>offset</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- byte offset in the object to begin writing at</p></li>
<li><p><strong>oncomplete</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-data docutils literal notranslate"><span class="pre">Callable</span></code>[[<code class="xref py py-class docutils literal notranslate"><span class="pre">Completion</span></code>], <code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code>]]) -- what to do when the write is safe and complete in memory
on all replicas</p></li>
<li><p><strong>onsafe</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-data docutils literal notranslate"><span class="pre">Callable</span></code>[[<code class="xref py py-class docutils literal notranslate"><span class="pre">Completion</span></code>], <code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code>]]) -- what to do when the write is safe and complete on storage
on all replicas</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Completion</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>completion object</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.aio_write_full">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">aio_write_full</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">to_write</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">oncomplete</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">onsafe</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.aio_write_full" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.aio_write_full(self, unicode object_name: str, bytes to_write: bytes, oncomplete: Optional[Callable] = None, onsafe: Optional[Callable] = None) -&gt; Completion</p>
<p>Asynchronously write an entire object</p>
<p>The object is filled with the provided data. If the object exists,
it is atomically truncated and then written.
Queues the write and returns.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>object_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the object</p></li>
<li><p><strong>to_write</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>) -- data to write</p></li>
<li><p><strong>oncomplete</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-data docutils literal notranslate"><span class="pre">Callable</span></code>]) -- what to do when the write is safe and complete in memory
on all replicas</p></li>
<li><p><strong>onsafe</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-data docutils literal notranslate"><span class="pre">Callable</span></code>]) -- what to do when the write is safe and complete on storage
on all replicas</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Completion</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>completion object</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.aio_append">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">aio_append</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">to_append</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">oncomplete</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">onsafe</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.aio_append" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.aio_append(self, unicode object_name: str, bytes to_append: bytes, oncomplete: Optional[Callable] = None, onsafe: Optional[Callable] = None) -&gt; Completion</p>
<p>Asynchronously append data to an object</p>
<p>Queues the write and returns.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>object_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the object</p></li>
<li><p><strong>to_append</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>) -- data to append</p></li>
<li><p><strong>offset</strong> -- byte offset in the object to begin writing at</p></li>
<li><p><strong>oncomplete</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-data docutils literal notranslate"><span class="pre">Callable</span></code>]) -- what to do when the write is safe and complete in memory
on all replicas</p></li>
<li><p><strong>onsafe</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-data docutils literal notranslate"><span class="pre">Callable</span></code>]) -- what to do when the write is safe and complete on storage
on all replicas</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Completion</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>completion object</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.write">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.write" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.write(self, unicode key: str, bytes data: bytes, int offset: int = 0)</p>
<p>Write data to an object synchronously</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the object</p></li>
<li><p><strong>data</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>) -- data to write</p></li>
<li><p><strong>offset</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- byte offset in the object to begin writing at</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">LogicError</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>int - 0 on success</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.write_full">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">write_full</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.write_full" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.write_full(self, unicode key: str, bytes data: bytes)</p>
<p>Write an entire object synchronously.</p>
<p>The object is filled with the provided data. If the object exists,
it is atomically truncated and then written.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the object</p></li>
<li><p><strong>data</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>) -- data to write</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>int - 0 on success</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.aio_flush">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">aio_flush</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.aio_flush" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.aio_flush(self)</p>
<p>Block until all pending writes in an io context are safe</p>
<dl class="field-list simple">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.set_locator_key">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">set_locator_key</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">loc_key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.set_locator_key" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.set_locator_key(self, unicode loc_key: str)</p>
<p>Set the key for mapping objects to pgs within an io context.</p>
<p>The key is used instead of the object name to determine which
placement groups an object is put in. This affects all subsequent
operations of the io context - until a different locator key is
set, all objects in this io context will be placed in the same pg.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>loc_key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- the key to use as the object locator, or NULL to discard
any previously set key</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.aio_read">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">aio_read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">length</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">oncomplete</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.aio_read" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.aio_read(self, unicode object_name: str, int length: int, int offset: int, oncomplete: Optional[Callable] = None) -&gt; Completion</p>
<p>Asynchronously read data from an object</p>
<p>oncomplete will be called with the returned read value as
well as the completion:</p>
<p>oncomplete(completion, data_read)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>object_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the object to read from</p></li>
<li><p><strong>length</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- the number of bytes to read</p></li>
<li><p><strong>offset</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- byte offset in the object to begin reading from</p></li>
<li><p><strong>oncomplete</strong> (<code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code>[<code class="xref py py-data docutils literal notranslate"><span class="pre">Callable</span></code>]) -- what to do when the read is complete</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Completion</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>completion object</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.read">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">length</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">8192</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.read" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.read(self, unicode key: str, int length: int = 8192, int offset: int = 0) -&gt; bytes</p>
<p>Read data from an object synchronously</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- name of the object</p></li>
<li><p><strong>length</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- the number of bytes to read (default=8192)</p></li>
<li><p><strong>offset</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- byte offset in the object to begin reading at</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>data read from object</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.stat">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">stat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.stat" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.stat(self, unicode key: str) -&gt; Tuple[int, time.struct_time]</p>
<p>Get object stats (size/mtime)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- the name of the object to get stats from</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-data docutils literal notranslate"><span class="pre">Tuple</span></code>[<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code>]</p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>(size,timestamp)</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.trunc">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">trunc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.trunc" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.trunc(self, unicode key: str, int size: int) -&gt; int</p>
<p>Resize an object</p>
<p>If this enlarges the object, the new area is logically filled with
zeroes. If this shrinks the object, the excess data is removed.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- the name of the object to resize</p></li>
<li><p><strong>size</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code>) -- the new size of the object in bytes</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>0 on success, otherwise raises error</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.remove_object">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">remove_object</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.remove_object" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.remove_object(self, unicode key: str) -&gt; bool</p>
<p>Delete an object</p>
<p>This does not delete any snapshots of the object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- the name of the object to delete</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>True on success</p>
</dd>
</dl>
</dd></dl>

</section>
<section id="id16">
<h3>对象的扩展属性<a class="headerlink" href="#id16" title="Permalink to this heading"></a></h3>
<p>你可以给一个对象设置扩展属性（ XATTR ）。你可以检出一些对象或扩展属性、并挨个迭代它们。</p>
<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.set_xattr">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">set_xattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xattr_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xattr_value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.set_xattr" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.set_xattr(self, unicode key: str, unicode xattr_name: str, bytes xattr_value: bytes) -&gt; bool</p>
<p>Set an extended attribute on an object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- the name of the object to set xattr to</p></li>
<li><p><strong>xattr_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- which extended attribute to set</p></li>
<li><p><strong>xattr_value</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>) -- the value of the  extended attribute</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>True on success, otherwise raise an error</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.get_xattrs">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">get_xattrs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">oid</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.get_xattrs" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.get_xattrs(self, unicode oid: str) -&gt; XattrIterator</p>
<p>Start iterating over xattrs on an object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>oid</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- the name of the object to get xattrs from</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">XattrIterator</span></code></p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>XattrIterator</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.XattrIterator.__next__">
<span class="sig-prename descclassname"><span class="pre">XattrIterator.</span></span><span class="sig-name descname"><span class="pre">__next__</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.XattrIterator.__next__" title="Permalink to this definition"></a></dt>
<dd><p>Get the next xattr on the object</p>
<dl class="field-list simple">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p>StopIteration</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>pair - of name and value of the next Xattr</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.get_xattr">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">get_xattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xattr_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.get_xattr" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.get_xattr(self, unicode key: str, unicode xattr_name: str) -&gt; bytes</p>
<p>Get the value of an extended attribute on an object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- the name of the object to get xattr from</p></li>
<li><p><strong>xattr_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- which extended attribute to read</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>value of the xattr</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.rm_xattr">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">rm_xattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xattr_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.rm_xattr" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.rm_xattr(self, unicode key: str, unicode xattr_name: str) -&gt; bool</p>
<p>Removes an extended attribute on from an object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- the name of the object to remove xattr from</p></li>
<li><p><strong>xattr_name</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) -- which extended attribute to remove</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeError</span></code></p>
</dd>
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Error</span></code></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>True on success, otherwise raise an error</p>
</dd>
</dl>
</dd></dl>

</section>
</section>
<section id="id17">
<h2>对象接口<a class="headerlink" href="#id17" title="Permalink to this heading"></a></h2>
<p>从一个 I/O 上下文，可以从一个存储池检出一些对象、并挨个迭代它们。
对象接口使得各个对象看起来像文件，你可以在对象上执行同步操作。
异步操作你应该用 I/O 上下文方法。</p>
<dl class="py method">
<dt class="sig sig-object py" id="rados.Ioctx.list_objects">
<span class="sig-prename descclassname"><span class="pre">Ioctx.</span></span><span class="sig-name descname"><span class="pre">list_objects</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Ioctx.list_objects" title="Permalink to this definition"></a></dt>
<dd><p>Ioctx.list_objects(self) -&gt; ObjectIterator</p>
<p>Get ObjectIterator on rados.Ioctx object.</p>
<dl class="field-list simple">
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ObjectIterator</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>ObjectIterator</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.ObjectIterator.__next__">
<span class="sig-prename descclassname"><span class="pre">ObjectIterator.</span></span><span class="sig-name descname"><span class="pre">__next__</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.ObjectIterator.__next__" title="Permalink to this definition"></a></dt>
<dd><p>Get the next object name and locator in the pool</p>
<dl class="field-list simple">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p>StopIteration</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>next rados.Ioctx Object</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Object.read">
<span class="sig-prename descclassname"><span class="pre">Object.</span></span><span class="sig-name descname"><span class="pre">read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">length</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1024</span> <span class="pre">*</span> <span class="pre">1024</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Object.read" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Object.write">
<span class="sig-prename descclassname"><span class="pre">Object.</span></span><span class="sig-name descname"><span class="pre">write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string_to_write</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Object.write" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Object.get_xattrs">
<span class="sig-prename descclassname"><span class="pre">Object.</span></span><span class="sig-name descname"><span class="pre">get_xattrs</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Object.get_xattrs" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Object.get_xattr">
<span class="sig-prename descclassname"><span class="pre">Object.</span></span><span class="sig-name descname"><span class="pre">get_xattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">xattr_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Object.get_xattr" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Object.set_xattr">
<span class="sig-prename descclassname"><span class="pre">Object.</span></span><span class="sig-name descname"><span class="pre">set_xattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">xattr_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xattr_value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Object.set_xattr" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Object.rm_xattr">
<span class="sig-prename descclassname"><span class="pre">Object.</span></span><span class="sig-name descname"><span class="pre">rm_xattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">xattr_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#rados.Object.rm_xattr" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Object.stat">
<span class="sig-prename descclassname"><span class="pre">Object.</span></span><span class="sig-name descname"><span class="pre">stat</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Object.stat" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="rados.Object.remove">
<span class="sig-prename descclassname"><span class="pre">Object.</span></span><span class="sig-name descname"><span class="pre">remove</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#rados.Object.remove" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../libradospp/" class="btn btn-neutral float-left" title="LibradosPP (C++)" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../libcephsqlite/" class="btn btn-neutral float-right" title="Ceph SQLite VFS" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>